﻿using System;
using Microsoft.Xna.Framework;

namespace Firefly.Framework.Input
{
    public class MouseAxisMap : InputMap, IPositionMapEx<Vector2, MouseManager, MouseAxisMapEventArgs>
    {
        public MouseAxisMap()
            : this(string.Empty)
        {
        }

        public MouseAxisMap(string action)
            : base()
        {
            InputMapType = InputMapType.MouseAxisMap;
            Action = action;
            InputService.Instance.RegisterInputMap(this);
        }

        #region IPositionMap Members

        public Vector2 CurrentPosition
        {
            get { return Manager.CurrentAxisPosition; }
        }
        public Vector2 PreviousPosition
        {
            get { return Manager.PreviousAxisPosition; }
        }
        public Vector2 PositionDelta
        {
            get { return Manager.AxisDelta; }
        }

        #endregion

        #region IPositionMapEx Members

        public event EventHandler<MouseAxisMapEventArgs> PositionChanged;

        private void NotifyPositionChanged()
        {
            EventHandler<MouseAxisMapEventArgs> handler = PositionChanged;

            if (handler != null)
            {
                handler(this, new MouseAxisMapEventArgs(this));
            }
        }

        #endregion

        #region IHasInputManager Members

        public MouseManager Manager { get; set; }

        #endregion

        #region IUpdateable Members

        public override void Update(GameTime gameTime)
        {
            if (Enabled)
            {
                if (PositionDelta != Vector2.Zero)
                {
                    NotifyPositionChanged();
                }
            }
        }

        #endregion
    }
}
